import pop from '../utils/pop';
import common from '../utils/common';
import axios from 'axios'

const errorHandler = error => {
	pop.error("文件上传失败，请稍候再试！");
	console.log(error);
}

export default {
	fileUpload(e,uploadType) {
		if(!uploadType){
			uploadType = "pic";
		}
		let file = e.target.files[0];
		let param = new FormData(); //创建form对象
		param.append("file", file, file.name); //通过append向form对象添加数据
		let config = {
			headers: {
				"Content-Type": "multipart/form-data"
			}
		}; //添加请求头
		//param.append("chunk", "0"); //添加form表单中其他数据
		//console.log(param.get("file")); //FormData私有类对象，访问不到，可以通过get判断值是否传进去
		return axios.post(common.getApiPrefix()+'/api/scapi/zhisuUploadFile?uploadType='+uploadType+"&r="+$.now(), param, config).catch(res => {
			errorHandler(res.data);
		});
	}
}